package com.guaoran.source.spring.framework.demo.action;


import com.guaoran.source.spring.framework.annotation.Autowried;
import com.guaoran.source.spring.framework.annotation.Controller;
import com.guaoran.source.spring.framework.annotation.RequestMapping;
import com.guaoran.source.spring.framework.annotation.RequestParam;
import com.guaoran.source.spring.framework.demo.service.MyService;
import com.guaoran.source.spring.framework.webmvc.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/web")
public class MyAction {
    @Autowried
    MyService myService;

    @RequestMapping("/index.html")
    public void query() {
        System.out.println("MyAction" + myService.get("query"));
    }

    @RequestMapping("/springmvc/demo")
    public ModelAndView demo(@RequestParam(value = "name") String name,String auth, HttpServletRequest request, HttpServletResponse response){
        String result = myService.get(name);
        Map<String,Object> model = new HashMap<String,Object>();
        model.put("result",result);
        model.put("date",new Date());
        model.put("auth",auth==null?"guaoran":auth);
        model.put("reference","gupao-@Tom");
        model.put("author","");
        return new ModelAndView("demo.html",model);
    }

}
